package com.tree.web;

import com.tree.entity.Rtree;
import com.tree.service.RtreeService;
import com.tree.util.HttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping(value = "/rtree")
public class RtreeController {

    @Autowired
    private RtreeService rtreeService;

    //获取古树列表
    @RequestMapping(value = "/getlist")
    private String getList(ModelMap modelMap, HttpServletRequest request){

        //获取当前页数
        int rowIndex = HttpUtil.getInt(request,"rowIndex");
        List<Rtree> list = new ArrayList<>();
        list = rtreeService.queryAll(rowIndex,10);
        modelMap.addAttribute("list",list);
        modelMap.addAttribute("rowIndex",rowIndex);
        return "rtree/rtrees";
    }

    //获取具体古树信息
    @RequestMapping(value = "/show")
    private String show(ModelMap modelMap, HttpServletRequest request){
        Rtree rtree = rtreeService.query(HttpUtil.getString(request,"treeName"));
//        System.out.println(HttpUtil.getString(request,"treeName"));
        modelMap.addAttribute("rtree",rtree);
        return "rtree/rtree";
    }
}
